const masterMind = (solution, guess) => {
  let m = 0, n = 0, arr = guess.split('');
  for (let i = 0; i < 4; i++) {
    if (solution[i] === guess[i]) m++;
    let j = arr.indexOf(solution[i])
    if (j !== -1) {
      n++
      arr.splice(j, 1)
    }
  }
  return [m, n - m]
}

console.log(masterMind('RGBY', 'GGRR'));